package cc.idoone.spring_boot_hello.config;

import cc.idoone.spring_boot_hello.interceptors.LogInterceptor;
import cc.idoone.spring_boot_hello.interceptors.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * HandlerInterceptor 配置
 *
 * @author hemj
 * @since 2017/10/22
 */
@Configuration
public class InterceptorsConfig extends WebMvcConfigurerAdapter {

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(logInterceptor())
				.addPathPatterns("/**")
				.excludePathPatterns("/static/**");
		registry.addInterceptor(loginInterceptor())
				.addPathPatterns("/simple/**");
		super.addInterceptors(registry);
	}

	public LogInterceptor logInterceptor() {
		return new LogInterceptor();
	}

	public LoginInterceptor loginInterceptor() {
		return new LoginInterceptor();
	}
}
